<?php

namespace App\Models;

use App\Models\Base\WorkUser as BaseWorkUser;

/**
 * 
 *
 * @property int $id
 * @property string $real_name 真实姓名
 * @property string|null $username 用户名
 * @property string $password 密码
 * @property string|null $tel 手机号
 * @property bool $enable 是否启用
 * @property string|null $memo 备注
 * @property string|null $token token
 * @property \Illuminate\Support\Carbon|null $expired_at 过期时间
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\WorkTicketRating> $ratings
 * @property-read int|null $ratings_count
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\School> $schools
 * @property-read int|null $schools_count
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\WorkTicketDetail> $ticketDetails
 * @property-read int|null $ticket_details_count
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\WorkTicket> $tickets
 * @property-read int|null $tickets_count
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\WorkTicketTransfer> $transfersFrom
 * @property-read int|null $transfers_from_count
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\WorkTicketTransfer> $transfersTo
 * @property-read int|null $transfers_to_count
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser query()
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser whereEnable($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser whereExpiredAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser whereMemo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser wherePassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser whereRealName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser whereTel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser whereToken($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser whereUsername($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser withTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|WorkUser withoutTrashed()
 * @mixin \Eloquent
 */
class WorkUser extends BaseWorkUser
{
	protected $fillable = [
		self::REAL_NAME,
		self::USERNAME,
		self::TEL,
		self::ENABLE,
		self::MEMO,
		self::TOKEN,
		self::EXPIRED_AT,
		self::PASSWORD,
	];

	protected $hidden = [
		self::PASSWORD,
	];

	public function schools()
	{
		return $this->belongsToMany(School::class, 'work_user_schools', 'work_user_id', 'school_id');
	}

	public function tickets()
	{
		return $this->hasMany(WorkTicket::class, WorkTicket::WORK_USER_ID, self::ID);
	}

	public function transfersFrom()
	{
		return $this->hasMany(WorkTicketTransfer::class, WorkTicketTransfer::FROM_WORK_USER_ID, self::ID);
	}

	public function transfersTo()
	{
		return $this->hasMany(WorkTicketTransfer::class, WorkTicketTransfer::TO_WORK_USER_ID, self::ID);
	}

	public function ratings()
	{
		return $this->hasMany(WorkTicketRating::class, WorkTicketRating::WORK_USER_ID, self::ID);
	}

	public function ticketDetails()
	{
		return  $this->morphMany(WorkTicketDetail::class, 'related', WorkTicketDetail::RELATED_TYPE, WorkTicketDetail::RELATED_ID);
	}
}
